package com.glela.order.service.impl.order;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.glela.common.constant.BaseConstants;
import com.glela.common.constant.BaseRestrictionsEnum;
import com.glela.common.constant.CommonConstants;
import com.glela.common.constant.GoodsSelfTypeEnum;
import com.glela.common.constant.GoodsTypeEnum;
import com.glela.common.constant.OpenStoreTypeEnum;
import com.glela.common.constant.PayTypeEnum;
import com.glela.common.constant.StatusEnum;
import com.glela.common.constant.UserJournalStatusEnum;
import com.glela.common.exception.PlatformException;
import com.glela.common.util.Config;
import com.glela.common.util.OrderUtil;
import com.glela.company.model.CompanyXz;
import com.glela.goods.mapper.InventoryMapper;
import com.glela.goods.mapper.ShareGoodsMapper;
import com.glela.goods.model.Inventory;
import com.glela.goods.model.LimitTimeSaleDetail;
import com.glela.goods.model.ShareGoods;
import com.glela.goods.model.vo.InventoryVo;
import com.glela.goods.model.vo.StoreVo;
import com.glela.goods.service.LimitTimeSaleDetailService;
import com.glela.goods.service.ShoppingCartService;
import com.glela.order.model.OrderDetail;
import com.glela.order.model.OrderInfo;
import com.glela.order.model.OrderObject;
import com.glela.order.model.OrderSettlement;
import com.glela.order.model.PayTypeConfig;
import com.glela.order.model.request.RequestGetOrderObject;
import com.glela.order.model.request.RequestOrderDetail;
import com.glela.order.model.response.RespAddOrderInfo;
import com.glela.order.model.response.RespGetOrderInfo;
import com.glela.order.model.vo.order.ErrorMsgGoods;
import com.glela.order.model.vo.order.OrderRecommendAndTeacherVo;
import com.glela.order.service.OrderTokenService;
import com.glela.order.service.impl.AbstractOrderServiceImpl;
import com.glela.order.util.StoreComparator;
import com.glela.order.util.UserPromotionComparator;
import com.glela.platform.constant.ErrorEnum;
import com.glela.platform.model.BaseRestrictions;
import com.glela.platform.model.ChangeProcessLog;
import com.glela.platform.model.User;
import com.glela.platform.model.UserAddress;
import com.glela.platform.model.UserInfo;
import com.glela.platform.model.UserJournal;
import com.glela.platform.model.UserPromotion;
import com.glela.platform.model.response.ResponseResultModel;
import com.glela.platform.model.response.ResponseUser;
import com.glela.platform.vo.GoodsSimpleVo;
import com.glela.platform.vo.UserPromotionVo;

@Service(value = "orderService")
@Order(1)
@Deprecated
public class OrderServiceImpl extends AbstractOrderServiceImpl {
	private static Logger				logger	= LoggerFactory.getLogger(OrderServiceImpl.class);
	@Autowired
	private InventoryMapper				inventoryMapper;
	@Autowired
	private ShoppingCartService			shoppingCartService;
	@Autowired
	private OrderTokenService			orderTokenService;
	@Autowired
	private LimitTimeSaleDetailService	limitTimeSaleDetailService;

	@Override
	public ResponseResultModel<RespGetOrderInfo> getToOrderInfo(RequestGetOrderObject requestGetOrderObject) {
		DateTime nowTime = new DateTime();//当前时间，以次时间为去结算开始时间点
		/*初始化返回结果*/
		RespGetOrderInfo respGetOrderInfo = new RespGetOrderInfo();
		respGetOrderInfo.setToken(requestGetOrderObject.getToken());

		List<GoodsSimpleVo> _avl_goods_list = new LinkedList<GoodsSimpleVo>();
		List<ErrorMsgGoods> _err_goods_list = new LinkedList<ErrorMsgGoods>();
		respGetOrderInfo.setGoodsSimpleVoList(_avl_goods_list);
		ResponseResultModel<RespGetOrderInfo> resultModel = new ResponseResultModel<RespGetOrderInfo>(ErrorEnum.C10000, respGetOrderInfo);

		/*校验基础信息合法性*/
		//当前登录人信息
		Long _login_user_id = requestGetOrderObject.getUserId();
		ResponseUser _login_user = userService.selectUserRoleById(_login_user_id);
		if (_login_user == null || _login_user.getUserId() == null) {
			resultModel.setError(ErrorEnum.C20111);
			resultModel.setMessage("用户信息异常，请联系客服处理");
			logger.error("登录用户{}无效-{}", _login_user_id, JSONObject.toJSONString(_login_user));
			return resultModel;
		}
		ResponseUser _store_user = userService.selectUserRoleByPersonId(_login_user.getRecommendFrom());
		if (_check_login_user(_login_user, _store_user, resultModel)) {
			return resultModel;
		}

		//购买商品明细
		if (CollectionUtils.isEmpty(requestGetOrderObject.getGoodsSimpleVoList())) {
			resultModel.setError(ErrorEnum.C20701);
			return resultModel;
		}
		//用户提交的购买商品信息（以库存id为主键归类）
		Map<Long, GoodsSimpleVo> _req_goods_map = new HashMap<Long, GoodsSimpleVo>();
		int i = 0;
		long _talentId = 0;

		for (GoodsSimpleVo req_goods : requestGetOrderObject.getGoodsSimpleVoList()) {
			if (i++ == 0) {
				_talentId = req_goods.getTalentId();
			} else if (req_goods.getTalentId() > 0 && req_goods.getTalentId() != _talentId) {//一笔交易只允许出现一个分享人
				resultModel.setError(ErrorEnum.C20780);
				resultModel.setMessage("分享商品每次只能购买同一个分享人的产品");
				return resultModel;
			}
			req_goods.setApplywelfareId(0);
			req_goods.setActivityType(0);
			//过滤失效商品
			if (_check_share_goods_and_talent(req_goods, resultModel)) {
				return resultModel;
			}

			if (req_goods.getInventoryId() < 1) {
				resultModel.setError(ErrorEnum.C20102);
				return resultModel;
			} else if (_req_goods_map.containsKey(req_goods.getInventoryId())) {
				resultModel.setError(ErrorEnum.C20133);
				return resultModel;
			} else {
				_req_goods_map.put(req_goods.getInventoryId(), req_goods);
			}
		}
		if (requestGetOrderObject.getGoodsSimpleVoList().size() != _req_goods_map.size()) {
			resultModel.setError(ErrorEnum.C20133);
			return resultModel;
		}

		/*计算商品库存、价格*/
		List<GoodsSimpleVo> _check_goods_list = orderDao.selectGetOrderGoodsInfo(requestGetOrderObject.getGoodsSimpleVoList());
		//		Map<Long, GoodsSimpleVo> _check_goods_map = new HashMap<Long, GoodsSimpleVo>();

		long _xz_sister_user_id = BaseConstants.XZ_SISTER;
		respGetOrderInfo.setTotalPrice(0);
		int _total_open_goods_sale_price = 0;//总开店商品销售价
		Set<Object> goodsIdSet = new HashSet<>();//购买商品id集合
		Set<Object> brandIdSet = new HashSet<>();//购买商品品牌id集合

		for (GoodsSimpleVo goodsSimpleVo : _check_goods_list) {
			if (goodsSimpleVo.getGoodsType() != GoodsTypeEnum.T1.getCode()) {
				resultModel.setError(ErrorEnum.C20807);
				resultModel.setMessage("只能购买B区商品");
				return resultModel;
			}
			try {
				if (goodsSimpleVo.getOnlineTime() == null || goodsSimpleVo.getOfflineTime() == null || goodsSimpleVo.getOnlineTime().getTime() - nowTime.getMillis() > 0 || goodsSimpleVo.getOfflineTime().getTime() - nowTime.getMillis() < 0) {
					_err_goods_list.add(_pack_error_msg_goods(goodsSimpleVo, ErrorEnum.C20401.getMessage()));
					continue;
				}
			} catch (Exception e) {
				_err_goods_list.add(_pack_error_msg_goods(goodsSimpleVo, ErrorEnum.C20401.getMessage()));
				continue;
			}
			Inventory _check_inventory = inventoryMapper.selectByPrimaryKey(goodsSimpleVo.getInventoryId());
			if (_check_inventory == null || _check_inventory.getStatus() != 1) {//无库存
				_err_goods_list.add(_pack_error_msg_goods(goodsSimpleVo, "无库存"));
				continue;
			}

			int _check_sale_price = 0;
			int _check_product_inventory_num = 0;
			GoodsSimpleVo _req_goods = _req_goods_map.get(goodsSimpleVo.getInventoryId());

			if (_req_goods == null || _check_inventory.getGoodId() != _req_goods.getGoodId()) {
				_err_goods_list.add(_pack_error_msg_goods(goodsSimpleVo, "商品已离家出走，暂时无法购买"));
				logger.error("下单商品与数据库数据出现不一致：{}", JSONObject.toJSONString(goodsSimpleVo));
				continue;
			}

			//判断商品是否为分时抢购商品
			LimitTimeSaleDetail _check_limit_time_sale_detail = limitTimeSaleDetailService.queryByProductId(goodsSimpleVo.getProductId(), nowTime.toDate());
			//判断库存、判断售价
			if (_check_limit_time_sale_detail == null) {
				long _price_user_id = _store_user.getUserId();
				if (_req_goods.getTalentId() > 0) {
					User _check_talent_store_user = userService.selectRecommendFromByUserId(_req_goods.getTalentId());
					if (_check_talent_store_user == null) {
						resultModel.setError(ErrorEnum.C20111);
						resultModel.setMessage("分享人无效");
						return resultModel;
					} else {
						_price_user_id = _check_talent_store_user.getId();
					}
				}

				if (_price_user_id == _xz_sister_user_id) {// 当前登录人的推荐人为： 校妆姐姐，所以取校妆姐姐价
					_check_sale_price = _check_inventory.getXzSalePrice();
				} else {// 当前登录人的推荐人为： 一般店主，所以取店主价
					_check_sale_price = _check_inventory.getSalePrice();
				}
				_check_product_inventory_num = _check_inventory.getInventoryNum();
			} else {
				_check_sale_price = _check_limit_time_sale_detail.getProductSalePrice();

				//校验分时抢购数量
				if (_check_limit_time_sale_detail.getSkuCount().intValue() < _req_goods.getQuantity()) {//总限购数
					_err_goods_list.add(_pack_error_msg_goods(goodsSimpleVo, "超过限购数"));
					continue;
				} else {//用户限购数
							//查询已购数（包含待支付,待发货,待收货,已完成,交易成功,交易关闭）
					Integer limitSaleNums = this.orderDetailMapper.selectLimitSaleNums(_login_user.getUserId(), _check_limit_time_sale_detail.getLimitTimeSaleId(), goodsSimpleVo.getProductId(), goodsSimpleVo.getInventoryId());
					if (limitSaleNums != null && (limitSaleNums + _req_goods.getQuantity() > _check_limit_time_sale_detail.getUserSkuCount())) {
						_err_goods_list.add(_pack_error_msg_goods(goodsSimpleVo, "超过每人限购数"));
						continue;
					}
				}

				if (_check_inventory.getInventoryNum() <= _check_limit_time_sale_detail.getSkuCount()) {
					_check_product_inventory_num = _check_inventory.getInventoryNum();
				} else {
					_check_product_inventory_num = _check_limit_time_sale_detail.getSkuCount();
				}
			}
			if (_req_goods.getQuantity() > _check_product_inventory_num) {//无库存
				_err_goods_list.add(_pack_error_msg_goods(goodsSimpleVo, "库存不足"));
				continue;
			}

			goodsSimpleVo.setSalePrice(_check_sale_price);
			if (_check_sale_price != _req_goods.getSalePrice()) {//价格不等
				goodsSimpleVo.setSalePriceDesc((_check_sale_price < _req_goods.getSalePrice() ? "已降￥" : "已涨￥") + ((_check_sale_price - _req_goods.getSalePrice()) / 100.0));
			}
			respGetOrderInfo.setTotalPrice(respGetOrderInfo.getTotalPrice() + _check_sale_price * _req_goods.getQuantity());

			//封装前端提交的商品信息
			goodsSimpleVo.setQuantity(_req_goods.getQuantity());
			goodsSimpleVo.setTalentSerialId(_req_goods.getTalentSerialId());
			goodsSimpleVo.setTalentShareGoodId(_req_goods.getTalentShareGoodId());
			goodsSimpleVo.setTalentId(_req_goods.getTalentId());

			_avl_goods_list.add(goodsSimpleVo);

			goodsIdSet.add(goodsSimpleVo.getGoodId());
			brandIdSet.add(goodsSimpleVo.getBrandId());
			//b区自营产品累计开店金额
			//			if (goodsSimpleVo.getSelfSupport() == GoodsSelfTypeEnum.T0.getCode() && goodsSimpleVo.getGoodsType() == GoodsTypeEnum.T1.getCode()) {//B区自主商品
			if (goodsSimpleVo.isOpenGoods()) {//累计开店商品金额
				if (!_login_user.isStoreLevel()) {//不是店主累加商品总价
					_total_open_goods_sale_price += goodsSimpleVo.getSalePrice() * goodsSimpleVo.getQuantity();
				}
			}
		}
		respGetOrderInfo.getErrorMsg().getInvalidGoods().addAll(_err_goods_list);
		if (CollectionUtils.isEmpty(_avl_goods_list)) {
			return resultModel;
		}
		//校验分佣关系
		if (_check_commission_relationship(_avl_goods_list.get(0).getTalentId(), _avl_goods_list.size(), _login_user, null, resultModel)) {
			return resultModel;
		}

		if (!_login_user.isStoreLevel()) {
			BaseRestrictions _open_store_self_fee = baseRestrictionsService.getBaseRestrictionsForCache(BaseRestrictionsEnum.T6.getText());
			if (_open_store_self_fee == null) {
				resultModel.setError(ErrorEnum.C20000);
				resultModel.setMessage("缺少开店配置");
				return resultModel;
			} else {
				if (_open_store_self_fee.getRestrictions() <= _total_open_goods_sale_price) {
					//校验是否已经有开店单
					List<OrderObject> _check_open_store_order_list = orderDao.selectOpenOrder(_login_user_id);
					if (CollectionUtils.isNotEmpty(_check_open_store_order_list)) {
						resultModel.setError(ErrorEnum.C21201);
						resultModel.setMessage("您已经下过开店订单，请完成或取消之前待付款订单");
						return resultModel;
					}
					respGetOrderInfo.setTotalPrice(respGetOrderInfo.getTotalPrice() - _total_open_goods_sale_price + _total_open_goods_sale_price * _open_store_self_fee.getExperience() / 100);
					//开店单打折
					for (GoodsSimpleVo valGoods : _avl_goods_list) {
						//						if (valGoods.getSelfSupport() == GoodsSelfTypeEnum.T0.getCode() && valGoods.getGoodsType() == GoodsTypeEnum.T1.getCode()) {
						if (valGoods.isOpenGoods()) {
							valGoods.setSalePrice(valGoods.getSalePrice() * _open_store_self_fee.getExperience() / 100);
							GoodsSimpleVo _req_goods = _req_goods_map.get(valGoods.getInventoryId());
							if (valGoods.getSalePrice() != _req_goods.getSalePrice()) {
								valGoods.setSalePriceDesc("首单礼" + (valGoods.getSalePrice() < _req_goods.getSalePrice() ? "已降￥" : "已涨￥") + ((valGoods.getSalePrice() - _req_goods.getSalePrice()) / 100.0));
							}
						}
					}
				}
			}
		}
		//计算可用优惠券
		//		List<UserPromotionVo> userPromotionList = userPromotionService.selectUserPromotionByUserIdEx(_login_user_id, _avl_goods_list);
		List<UserPromotionVo> userPromotionList = userPromotionService.selectUserPromotion(_login_user_id, brandIdSet, goodsIdSet);
		getUserPromotionOrderList(userPromotionList, _avl_goods_list);
		respGetOrderInfo.setUserPromotionList(userPromotionList);
		//计算运费
		BaseRestrictions _check_freight_restriction = baseRestrictionsService.getBaseRestrictionsForCache(BaseRestrictionsEnum.FULL_FREE_FREIGHT);
		if (_check_freight_restriction != null && _check_freight_restriction.getRestrictions() > respGetOrderInfo.getTotalPrice()) {
			respGetOrderInfo.setFreight(_check_freight_restriction.getExperience());
		} else {
			respGetOrderInfo.setFreight(_get_default_freight());
		}
		respGetOrderInfo.setPayTypeConfigList(getPayType());
		respGetOrderInfo.setPayable(true);
		orderTokenService.addToken(respGetOrderInfo.getToken(), _login_user_id);
		return resultModel;
	}

	@Override
	public ResponseResultModel<RespAddOrderInfo> addOrderInfo(RequestOrderDetail requestOrderDetail) throws PlatformException {
		DateTime nowTime = new DateTime();//当前时间，以次时间为去结算开始时间点
		long nowTimeMillis = nowTime.getMillis();
		RespAddOrderInfo respAddOrderInfo = new RespAddOrderInfo();
		List<ErrorMsgGoods> _err_goods_list = new LinkedList<ErrorMsgGoods>();
		ResponseResultModel<RespAddOrderInfo> resultModel = new ResponseResultModel<RespAddOrderInfo>(ErrorEnum.C10000, respAddOrderInfo);

		if ((CollectionUtils.isEmpty(requestOrderDetail.getOrderDetailList()) || requestOrderDetail.getDeliveryWay() == null || requestOrderDetail.getPayType() == null) || (requestOrderDetail.getDeliveryWay() != 2 && requestOrderDetail.getMemberDeliveryAddressId() == null)) {
			resultModel.setError(ErrorEnum.C20102);
			return resultModel;
		}
		if (!orderTokenService.removeToken(requestOrderDetail.getToken())) {
			resultModel.setError(ErrorEnum.C20001);
			return resultModel;
		}

		List<OrderDetail> _req_order_detail_list = requestOrderDetail.getOrderDetailList();
		//当前登录人信息
		Long _login_user_id = requestOrderDetail.getUserId();
		ResponseUser _login_user = userService.selectUserRoleById(_login_user_id);
		if (_login_user == null || _login_user.getUserId() == null) {
			resultModel.setError(ErrorEnum.C20111);
			return resultModel;
		}
		ResponseUser _store_user = userService.selectUserRoleByPersonId(_login_user.getRecommendFrom());
		if (_check_login_user(_login_user, _store_user, resultModel)) {
			return resultModel;
		}
		//用户现金币不能超额支付
		if (_login_user.getMoney().longValue() < requestOrderDetail.getCashCoin()) {
			resultModel.setError(ErrorEnum.C20125);
			return resultModel;
		}
		//购买商品明细
		if (CollectionUtils.isEmpty(_req_order_detail_list)) {
			resultModel.setError(ErrorEnum.C20701);
			return resultModel;
		}
		//用户配送地址
		UserAddress userAddress = userAddressService.selectUserAddressById(requestOrderDetail.getMemberDeliveryAddressId());
		if (userAddress == null) {
			resultModel.setError(ErrorEnum.C20129);
			return resultModel;
		}

		//如果商品归属分类 （1.正常2.福利社 3体验）为空，默认为0
		if (_req_order_detail_list.get(0).getApplywelfareId() == null) {
			_req_order_detail_list.get(0).setApplywelfareId(0);
		}
		Map<Long, InventoryVo> _check_inventory_map = new HashMap<Long, InventoryVo>();
		createInventoryMap(_check_inventory_map, _req_order_detail_list);

		List<OrderDetail> _avl_goods_list = new LinkedList<OrderDetail>();
		long _xz_sister_user_id = BaseConstants.XZ_SISTER;
		int _total_open_goods_sale_price = 0;//总开店商品销售价
		int totalPrice = 0;//总销售金额
		//		Map<Integer, Integer> openStoreSelfFeeMap = new HashMap<Integer, Integer>();//B区店铺自有商品应付总金额,
		int _diff_total_price = 0;//价格变动差价综合
		int k = 0;
		long _talentId = 0;
		boolean _has_self_goods = false;//有自主产品
		boolean _has_noself_goods = false;//有非自主产品
		for (OrderDetail _req_order_detail : _req_order_detail_list) {
			_req_order_detail.setUserId(_login_user.getUserId());
			if (k++ == 0) {
				_talentId = _req_order_detail.getTalentId() == null ? 0 : _req_order_detail.getTalentId();
			} else if (_req_order_detail.getTalentId() != null && _req_order_detail.getTalentId().longValue() > 0 && _req_order_detail.getTalentId().longValue() != _talentId) {
				//每笔交易只允许出现一个分享人
				resultModel.setError(ErrorEnum.C20780);
				resultModel.setMessage("分享商品每次只能购买同一个分享人的产品");
				return resultModel;
			}

			/*校验*/
			if (_check_share_goods_and_talent(_req_order_detail.getGoodId(), _req_order_detail.getTalentId(), _req_order_detail.getTalentShareGoodId(), resultModel)) {
				_check_inventory_map.remove(_req_order_detail.getInventoryId());
				return resultModel;
			}

			InventoryVo _check_inventory = _check_inventory_map.get(_req_order_detail.getInventoryId());
			if (_check_inventory == null || _check_inventory.getStatus() != 1 || _check_inventory.getInventoryNum() <= 0) {
				_err_goods_list.add(_pack_error_msg_goods(_req_order_detail, "库存不足"));
				_check_inventory_map.remove(_req_order_detail.getInventoryId());
				continue;
			}
			_check_inventory.setApplywelfareId(0);
			_req_order_detail.setApplywelfareId(0);
			_req_order_detail.setActivityType(0);

			//1：b、c区商品不能一同支付
			if (_req_order_detail.getGoodsType() != GoodsTypeEnum.T1.getCode()) {
				_err_goods_list.add(_pack_error_msg_goods(_req_order_detail, "只能购买B区商品"));
				_check_inventory_map.remove(_req_order_detail.getInventoryId());
				continue;
			}
			//2：下单商品必须上架可售
			if (_check_inventory.isNotOnTheShelf(nowTimeMillis)) {
				_err_goods_list.add(_pack_error_msg_goods(_req_order_detail, ErrorEnum.C20401.getMessage()));
				_check_inventory_map.remove(_req_order_detail.getInventoryId());
				continue;
			}

			int _check_sale_price = 0;
			int _check_product_inventory_num = 0;

			//判断商品是否为分时抢购商品
			LimitTimeSaleDetail _check_limit_time_sale_detail = limitTimeSaleDetailService.queryByProductId(_check_inventory.getProductId(), nowTime.toDate());
			//判断库存、判断售价
			if (_check_limit_time_sale_detail == null) {
				long _price_user_id = _store_user.getUserId();
				if (_req_order_detail.getTalentId() > 0) {
					User _check_talent_store_user = userService.selectRecommendFromByUserId(_req_order_detail.getTalentId());
					if (_check_talent_store_user == null) {
						resultModel.setError(ErrorEnum.C20111);
						resultModel.setMessage("分享人无效");
						return resultModel;
					} else {
						_price_user_id = _check_talent_store_user.getId();
					}
				}

				if (_price_user_id == _xz_sister_user_id) {// 当前登录人的推荐人为： 校妆姐姐，所以取校妆姐姐价
					_check_sale_price = _check_inventory.getXzSalePrice();
				} else {// 当前登录人的推荐人为： 一般店主，所以取店主价
					_check_sale_price = _check_inventory.getSalePrice();
				}
				_check_product_inventory_num = _check_inventory.getInventoryNum();
			} else {
				_req_order_detail.setLimitTimeSaleId(_check_limit_time_sale_detail.getLimitTimeSaleId());
				_req_order_detail.setLimitTimeSaleDetailId(_check_limit_time_sale_detail.getId());
				_check_sale_price = _check_limit_time_sale_detail.getProductSalePrice();

				//校验分时抢购数量
				if (_check_limit_time_sale_detail.getSkuCount().intValue() < _req_order_detail.getQuantity()) {//总限购数
					_err_goods_list.add(_pack_error_msg_goods(_req_order_detail, "超过限购数"));
					continue;
				} else {//用户限购数
							//查询已购数（包含待支付,待发货,待收货,已完成,交易成功,交易关闭）
					Integer limitSaleNums = this.orderDetailMapper.selectLimitSaleNums(_login_user.getUserId(), _check_limit_time_sale_detail.getLimitTimeSaleId(), _check_inventory.getProductId(), _check_inventory.getId());
					if (limitSaleNums != null && limitSaleNums + _req_order_detail.getQuantity() > _check_limit_time_sale_detail.getUserSkuCount()) {
						_err_goods_list.add(_pack_error_msg_goods(_req_order_detail, "超过每人限购数"));
						continue;
					}
				}

				if (_check_inventory.getInventoryNum() <= _check_limit_time_sale_detail.getSkuCount()) {
					_check_product_inventory_num = _check_inventory.getInventoryNum();
				} else {
					_check_product_inventory_num = _check_limit_time_sale_detail.getSkuCount();
				}
			}
			if (_req_order_detail.getQuantity() > _check_product_inventory_num) {//无库存
				_err_goods_list.add(_pack_error_msg_goods(_req_order_detail, "库存不足"));
				_check_inventory_map.remove(_req_order_detail.getInventoryId());
				continue;
			}

			if (_check_sale_price != _req_order_detail.getSalePrice()) {//价格不等
				_diff_total_price += (_req_order_detail.getSalePrice() - _check_sale_price) * _req_order_detail.getQuantity().intValue();
			}
			//			_req_order_detail.setSalePrice(_check_sale_price);
			_check_inventory.setSalePrice(_check_sale_price);

			//			if (_check_inventory.getSelfSupport() == GoodsSelfTypeEnum.T0.getCode() && _req_order_detail.getGoodsType() == GoodsTypeEnum.T1.getCode()) {//b区自营商品
			if (_check_inventory.isOpenGoods()) {
				if (!_login_user.isStoreLevel()) {//不是店主累计商品销售额
					_total_open_goods_sale_price += _check_inventory.getSalePrice() * _req_order_detail.getQuantity();
					//					if (openStoreSelfFeeMap.get(_req_order_detail.getStoreId()) == null) {
					//						openStoreSelfFeeMap.put(_req_order_detail.getStoreId(), _check_inventory.getSalePrice() * _req_order_detail.getQuantity());
					//					} else {
					//						openStoreSelfFeeMap.put(_req_order_detail.getStoreId(), openStoreSelfFeeMap.get(_req_order_detail.getStoreId()) + _check_inventory.getSalePrice() * _req_order_detail.getQuantity());
					//					}
				}
			}

			//累加总销售金额
			totalPrice += _check_inventory.getSalePrice() * _req_order_detail.getQuantity().intValue();

			_has_self_goods = _check_inventory.getSelfSupport() == GoodsSelfTypeEnum.T0.getCode();
			_has_noself_goods = _check_inventory.getSelfSupport() == GoodsSelfTypeEnum.T1.getCode();
			_avl_goods_list.add(_req_order_detail);
		}
		respAddOrderInfo.getErrorMsg().getInvalidGoods().addAll(_err_goods_list);
		if (CollectionUtils.isEmpty(_avl_goods_list)) {
			resultModel.setError(ErrorEnum.C20701);
			return resultModel;
		}

		String recommendFrom = BaseConstants.XZ_SISTER_PERSION_ID;//推荐人身份ID
		String talentTeacher = "";//达人导师/经纪人身份id
		OrderRecommendAndTeacherVo orderRecommendAndTeacherVo = new OrderRecommendAndTeacherVo();
		if (_check_commission_relationship(_avl_goods_list.get(0).getTalentId(), _avl_goods_list.size(), _login_user, orderRecommendAndTeacherVo, resultModel)) {
			return resultModel;
		} else {
			recommendFrom = orderRecommendAndTeacherVo.getRecommendFrom();
			talentTeacher = orderRecommendAndTeacherVo.getTalentTeacher();
		}

		//是否是首单
		//获取开店订单优惠比例且标注此单是否为开店单
		int isOpenStore = 0;
		int experience = 0;//开店单打折比例（百分制）
		Map<String, BaseRestrictions> baseRestrictionsMap = selectAllBaseRestrictions();
		BaseRestrictions baseRestrictionsForCache = baseRestrictionsService.getBaseRestrictionsForCache(BaseRestrictionsEnum.T6);
		if (baseRestrictionsForCache == null || baseRestrictionsForCache.getExperience() <= 0 || baseRestrictionsForCache.getRestrictions() < 0) {
			resultModel.setError(ErrorEnum.C20107);
			logger.error("系统常量配置异常：{}", BaseRestrictionsEnum.T6.getText());
			return resultModel;
		}
		experience = baseRestrictionsForCache.getExperience();
		if (_total_open_goods_sale_price >= baseRestrictionsForCache.getRestrictions()) {//满足开店条件
			isOpenStore = 1;//标识开店单
			if (experience != 100) {//开店优惠
				//销售价打折
				totalPrice = _diff_total_price = 0;
				for (OrderDetail orderDetail : _avl_goods_list) {
					InventoryVo _check_inventory = _check_inventory_map.get(orderDetail.getInventoryId());
					//					if (_check_inventory.getSelfSupport() == GoodsSelfTypeEnum.T0.getCode()) {
					if (_check_inventory.isOpenGoods()) {
						_check_inventory.setSalePrice(_check_inventory.getSalePrice() * experience / 100);
					}
					_diff_total_price += (orderDetail.getSalePrice() - _check_inventory.getSalePrice()) * orderDetail.getQuantity().intValue();
					totalPrice += _check_inventory.getSalePrice() * orderDetail.getQuantity().intValue();
				}
			}
		}
		if (_diff_total_price != 0) {
			if (_diff_total_price < 0) {
				respAddOrderInfo.getErrorMsg().setDesPriceChanger("商品价格发生变动，累计涨价￥" + (_diff_total_price / -100.0));
				return resultModel;
			} else {
				respAddOrderInfo.getErrorMsg().setDesPriceChanger("商品价格发生变动，累计降价￥" + (_diff_total_price / 100.0));
			}
		}

		/*优惠券*/
		UserPromotion userPromotion = null;
		if (requestOrderDetail.getPromotionId() > 0) {
			userPromotion = userPromotionService.selectUserPromotionByPromotionDetailIdAndUserId(requestOrderDetail.getPromotionId(), _avl_goods_list.get(0).getUserId());
			if (userPromotion == null || userPromotion.getPromotionNumber() <= 0 || (userPromotion.getType() == 7 && (userPromotion.getTargetSelfType() == GoodsSelfTypeEnum.T0.getCode() && _has_noself_goods && userPromotion.getTargetSelfType() == GoodsSelfTypeEnum.T1.getCode() && _has_self_goods))) {
				resultModel.setError(ErrorEnum.C30110);
				return resultModel;
			}
			//二次校验优惠券可用性
			if (userPromotion.getIsDiscount() == 0) {//满xx可使用优惠券
				if (userPromotion.getLimited() > totalPrice) {
					resultModel.setError(ErrorEnum.C30110);
					return resultModel;
				}
			} else if (userPromotion.getIsDiscount() == 1) {//折扣优惠
				//TODO 折扣率未校验
			}
		}

		/*活动*/
		//		Activity activity = null;

		/*事务回滚开始*/
		if (!orderTokenService.removeToken(requestOrderDetail.getToken())) {//防重复提交
			resultModel.setError(ErrorEnum.C20001);
			return resultModel;
		}
		/*生成交易单*/
		OrderObject orderObject = new OrderObject();
		orderObject.setOpenStore(isOpenStore);//累计开店及购买了开店商品，标记开店单
		//扣除用户本次现金币
		if (requestOrderDetail.getCashCoin() > 0) {
			int umResult = userService.updateSubMoneyById(_login_user.getUserId(), requestOrderDetail.getCashCoin());
			if (umResult == 0) {//本次现金币支付不可用，设置现金币花费为0
				resultModel.setError(ErrorEnum.C20125);
				return resultModel;
			}
			//开始记录日志
			ChangeProcessLog Log = new ChangeProcessLog();
			Log.setDescription("妆币抵扣现金[生成订单]");
			Log.setMethod("OrderServiceImpl.addOrderInfo");
			Log.setPrimaryID(String.valueOf(_login_user.getUserId()));
			Log.setTableName("yg_user.c_user");
			Log.getBeforeMap().put("Money", _login_user.getMoney());
			Log.getAfterMap().put("Money", _login_user.getMoney() - requestOrderDetail.getCashCoin());
			LogMapper.insert(Log);
		}
		if (requestOrderDetail.getPromotionId() > 0) {//使用优惠券
			//FIXME 查找前端提交优惠券信息，但未对此优惠券有效性进行验证
			int upResult = userPromotionService.updateSubUserPromotionNumber(requestOrderDetail.getPromotionId(), _login_user.getUserId());
			if (upResult != 1) {//FIXME 优惠券未使用，没有将优惠券置空，后续代码又根据此优惠券进行处理
				logger.error("用户" + _login_user.getUserId() + "的优惠券" + requestOrderDetail.getPromotionId() + "不可用");
				throw new PlatformException(ErrorEnum.C30110, "优惠券不可用");
			}
		}
		//生成交易单号
		StringBuffer orderSn = new StringBuffer();
		orderSn.append(CommonConstants.ORDER_OBJECT_PREFIX).append(OrderUtil.getOrderSn());
		orderObject.setOrderSn(orderSn.toString());
		respAddOrderInfo.setOrderSn(orderObject.getOrderSn());

		//根据订单商品店铺id排序
		Collections.sort(_avl_goods_list, new StoreComparator());
		List<OrderInfo> orderInfoList = new ArrayList<OrderInfo>();
		int i = 0;
		int storeId = 0;
		StoreVo storeVo = null;

		int totalSettlementPrice = 0;//总结算金额
		Map<Integer, Integer> bgSalePriceMap = new HashMap<Integer, Integer>();//按品牌及商品分类统计销售总金额
		Map<Integer, Integer> oiTotalPriceMap = new HashMap<Integer, Integer>();//店铺实际总销售金额
		Map<Integer, Integer> oiTotalSettlementPriceMap = new HashMap<Integer, Integer>();//店铺实际总结算金额
		Map<String, Integer> oinfoBGSalePriceMap = new HashMap<String, Integer>();
		for (OrderDetail orderDetail : _avl_goods_list) {
			//扣减库存
			int inResult = orderDao.subInventoryNumById(orderDetail.getInventoryId(), orderDetail.getQuantity());
			if (inResult != 1) {
				throw new PlatformException(ErrorEnum.C20409, orderDetail.getGoodName() + ErrorEnum.C20409.getMessage());
			}
			if (orderDetail.getLimitTimeSaleId() != 0) {//分时抢购限购数
				int subSkuCountNums = limitTimeSaleDetailMapper.updateSubSkuCount(_login_user.getUserId(), orderDetail.getLimitTimeSaleId(), orderDetail.getLimitTimeSaleDetailId(), orderDetail.getProductId(), orderDetail.getInventoryId(), orderDetail.getQuantity());
				if (subSkuCountNums != 1) {
					throw new PlatformException(ErrorEnum.C20409, orderDetail.getGoodName() + "超过每人限购数");
				}
			}

			if (i == 0) {//生成交易单
				createOrderObject(orderObject, orderDetail, requestOrderDetail, userAddress);
			}
			//店铺id不同，生成新的订单
			if (orderDetail.getStoreId().intValue() != storeId) {
				storeVo = brandService.getStoreById(orderDetail.getStoreId().intValue());
				OrderInfo orderInfo = new OrderInfo();
				createOrderInfo(orderInfo, orderDetail, requestOrderDetail, storeVo, userAddress);
				orderInfoList.add(orderInfo);
			}

			//累加店铺总销售金额
			InventoryVo _check_inventory = _check_inventory_map.get(orderDetail.getInventoryId());
			if (oiTotalPriceMap.get(orderDetail.getStoreId()) == null) {
				oiTotalPriceMap.put(orderDetail.getStoreId(), _check_inventory.getSalePrice() * orderDetail.getQuantity());
			} else {
				oiTotalPriceMap.put(orderDetail.getStoreId(), oiTotalPriceMap.get(orderDetail.getStoreId()) + _check_inventory.getSalePrice() * orderDetail.getQuantity());
			}
			//累加店铺总结算金额
			if (oiTotalSettlementPriceMap.get(orderDetail.getStoreId()) == null) {
				oiTotalSettlementPriceMap.put(orderDetail.getStoreId(), _check_inventory.getSettlementPrice() * orderDetail.getQuantity());
			} else {
				oiTotalSettlementPriceMap.put(orderDetail.getStoreId(), oiTotalSettlementPriceMap.get(orderDetail.getStoreId()) + _check_inventory.getSettlementPrice() * orderDetail.getQuantity());
			}
			//累加总结算金额
			totalSettlementPrice += _check_inventory.getSettlementPrice() * orderDetail.getQuantity();
			//用户使用了优惠券
			if (requestOrderDetail.getPromotionId() != 0 && userPromotion != null) {
				createBGSalePriceMap(bgSalePriceMap, userPromotion, orderDetail, _check_inventory_map);
				createOInfoBGSalePriceMap(oinfoBGSalePriceMap, userPromotion, orderDetail, _check_inventory_map);
			}
			//xz old
			//设置校验店铺id为当前店铺id
			storeId = orderDetail.getStoreId();
			i++;
		}
		//设置总销售金额
		orderObject.setTotalPrice(totalPrice);
		//			Map<String,BaseRestrictions> baseRestrictionsMap=selectAllBaseRestrictions();
		//			int experience=compOpenStorePrice(baseRestrictionsMap,openStoreSelfFee, orderObject);
		//设置总结算金额
		orderObject.setTotalSettlementPrice(totalSettlementPrice);
		//计算整单优惠券抵扣金额
		int promotionDiscount = compOOPomotionDiscount(userPromotion, orderObject, bgSalePriceMap);
		orderObject.setPromotionDiscount(promotionDiscount);
		//设置运费
		BaseRestrictions Restrictions = baseRestrictionsService.getBaseRestrictionsForCache(BaseRestrictionsEnum.FULL_FREE_FREIGHT);
		if (Restrictions != null && Restrictions.getRestrictions() > orderObject.getTotalPrice().intValue()) {
			orderObject.setFreight(Restrictions.getExperience());
		} else {
			orderObject.setFreight(_get_default_freight());
		}
		orderObject.setTotalFee(orderObject.getTotalPrice() + orderObject.getFreight() - orderObject.getPromotionDiscount() - orderObject.getCashCoin());
		if (orderObject.getTotalFee().intValue() < orderObject.getFreight()) {//如果实付总金额小于0，默认付邮费
			if (orderObject.getCashCoin().intValue() > 0) {
				throw new PlatformException(ErrorEnum.C21212, ErrorEnum.C21212.getDesc());
			}
			orderObject.setPromotionDiscount(orderObject.getPromotionDiscount().intValue() + orderObject.getTotalFee().intValue() - orderObject.getFreight().intValue());
			orderObject.setTotalFee(orderObject.getFreight());
		}
		// orderObject.setCommisionFee(commisionFee);
		//设置交易订单店中店用户id
		if (_avl_goods_list.get(0).getTalentId() > 0) {
			orderObject.setOpenStoreUserId(_avl_goods_list.get(0).getTalentId());
		} else {
			orderObject.setOpenStoreUserId(_store_user.getUserId());
		}

		//生成交易订单
		int ooResult = orderDao.insertOrderObjectSelective(orderObject);
		if (ooResult != 1) {
			throw new PlatformException(ErrorEnum.C20000, ErrorEnum.C20000.getMessage());
		}

		/*设置订单信息*/
		Map<Integer, Long> orderInfoStoreIdMap = new HashMap<Integer, Long>();//以店铺为索引的订单主键集合
		Map<Long, OrderInfo> orderInfoIdMap = new HashMap<Long, OrderInfo>();//以订单主键为索引的订单信息集合
		//		int oiAllTotalFee = 0;//所有订单应付金额累计和
		int ii = 0;
		int oiPreTotalCashCoin = 0;//所有订单现金币累计和
		int oiPreTotalPomotionDiscount = 0;//所有订单优惠抵扣累计和
		int oiLastPomotionDiscount = 0;//最后一笔订单优惠抵扣金额
		int oiLastPomotionDiscountII = 0;//最后一笔订单下标
		int oiPreFreight = 0;//所有订单运费累计和
		for (OrderInfo orderInfo : orderInfoList) {
			if (orderInfo.getFreight() == null) {//运费为空，置为0
				orderInfo.setFreight(0);
			}
			orderInfo.setTotalPrice(oiTotalPriceMap.get(orderInfo.getStoreId()));
			//				compOpenStoreInfoPrice(experience,openStoreSelfFeeMap,openStoreSelfFee,orderObject,orderInfo);
			//按店铺销售总金额占比，分摊总运费（丢失的精度放到最后一单运费）
			orderInfo.setFreight((int) (orderInfo.getTotalPrice().doubleValue() / orderObject.getTotalPrice() * orderObject.getFreight()));
			if (ii == orderInfoList.size() - 1) {
				orderInfo.setFreight(orderObject.getFreight() - oiPreFreight);
			}

			//订单结算金额
			orderInfo.setTotalSettlementPrice(oiTotalSettlementPriceMap.get(orderInfo.getStoreId()));

			//按店铺销售总金额占比总销售金额比例，分摊现金币（丢失精度放到最后一单现金币）
			int cashCoin = ((Double) (orderInfo.getTotalPrice().doubleValue() / orderObject.getTotalPrice() * orderObject.getCashCoin())).intValue();
			if (ii == orderInfoList.size() - 1) {
				cashCoin = orderObject.getCashCoin() - oiPreTotalCashCoin;
			}
			orderInfo.setCashCoin(cashCoin);

			//订单优惠
			orderInfo.setPromotionId(orderObject.getPromotionId());
			int oinfoPromotionDiscount = compOIPomotionDiscount(userPromotion, orderObject, orderInfo, oinfoBGSalePriceMap, bgSalePriceMap);
			if (oinfoPromotionDiscount == -1) {//没有分摊到总优惠调整金额
				oinfoPromotionDiscount = 0;
			} else {
				oiLastPomotionDiscount = oinfoPromotionDiscount;
				oiLastPomotionDiscountII = ii;
			}
			orderInfo.setPromotionDiscount(oinfoPromotionDiscount);

			//订单实付金额
			int totalFee = orderInfo.getTotalPrice() + orderInfo.getFreight() - orderInfo.getPromotionDiscount() - orderInfo.getCashCoin();
			if (totalFee <= 0) {//实付金额小于等于0，设置应付金额为运费
				totalFee = orderInfo.getFreight();
			}
			orderInfo.setTotalFee(totalFee);

			orderInfo.setCommisionFee(0);//分佣金额
			orderInfo.setOrderObjectId(orderObject.getId());
			//				int oiResult = orderDao.insertOrderInfoSelective(orderInfo);
			//				if (oiResult != 1) {
			//					throw new PlatformException(ErrorEnum.C20000, ErrorEnum.C20000.getMessage());
			//				}
			//				orderInfoStoreIdMap.put(orderInfo.getStoreId(), orderInfo.getId());
			//				orderInfoIdMap.put(orderInfo.getId(), orderInfo);
			//			oiAllTotalFee += totalFee;
			oiPreTotalCashCoin += orderInfo.getCashCoin();
			oiPreTotalPomotionDiscount += orderInfo.getPromotionDiscount();
			oiPreFreight += orderInfo.getFreight();
			ii++;
		}
		//计算最后一笔订单优惠抵扣金额（处理上面按比例分摊时的精度缺失问题，把缺失的部分放到最后一笔订单上）
		orderInfoList.get(oiLastPomotionDiscountII).setPromotionDiscount(orderObject.getPromotionDiscount() - (oiPreTotalPomotionDiscount - oiLastPomotionDiscount));
		//重新计算实付金额
		int infoTotalFee = orderInfoList.get(oiLastPomotionDiscountII).getTotalPrice() + orderInfoList.get(oiLastPomotionDiscountII).getFreight() - orderInfoList.get(oiLastPomotionDiscountII).getPromotionDiscount() - orderInfoList.get(oiLastPomotionDiscountII).getCashCoin();
		orderInfoList.get(oiLastPomotionDiscountII).setTotalFee(infoTotalFee);

		//计算总额
		infoTotalFee = 0;
		for (OrderInfo o : orderInfoList) {
			infoTotalFee += o.getTotalFee();
		}
		//子单支付金额总和和父单不一致
		if (infoTotalFee != orderObject.getTotalFee()) {
			//开始记录日志
			ChangeProcessLog Log = new ChangeProcessLog();
			Log.setMethod("AbstractOrderServiceImpl.addOrderObject");
			Log.setPrimaryID("");
			Log.setDescription(ErrorEnum.C20288.getMessage());
			Log.setTableName("yg_order.order");
			Log.getBeforeMap().put("order", JSON.toJSONString(orderInfoList));
			LogMapper.insert(Log);
			//throw new PlatformException(ErrorEnum.C20288, ErrorEnum.C20288.getMessage());
		}
		//把订单存数到数据库
		for (OrderInfo orderInfo : orderInfoList) {
			int oiResult = orderDao.insertOrderInfoSelective(orderInfo);
			if (oiResult != 1) {
				throw new PlatformException(ErrorEnum.C20000, ErrorEnum.C20000.getMessage());
			}
			//整理订单相关索引数据，用于下面生成订单商品明细
			orderInfoStoreIdMap.put(orderInfo.getStoreId(), orderInfo.getId());
			orderInfoIdMap.put(orderInfo.getId(), orderInfo);
		}
		// int oiResult = orderDao.batchInsertOrderInfo(orderInfoList);
		// if (oiResult < orderInfoList.size()) {
		// throw new PlatformException(ErrorEnum.C20000,
		// ErrorEnum.C20000.getMessage());
		// }

		/*生成订单商品明细*/
		Map<Long, Integer> odAllTotalFeeMap = new HashMap<Long, Integer>();//按订单分类，累加商品应付金额
		Map<Long, Integer> odAllCashCoinMap = new HashMap<Long, Integer>();
		Map<Long, Integer> odAllPomotionDiscountMap = new HashMap<Long, Integer>();
		Map<Long, int[]> odLastPomotionDiscountMap = new HashMap<Long, int[]>();//订单最后一个商品优惠抵扣金额（用于处理精度缺失问题）

		//封装订单商品明细
		for (int j = 0; j < _avl_goods_list.size(); j++) {
			OrderDetail orderDetail = _avl_goods_list.get(j);
			orderDetail.setRecommendFrom(recommendFrom);//普通推荐人身份id
			orderDetail.setMemberRecommend(_login_user.getMemberRecommend());//会员推荐人
			orderDetail.setTalentTeacher(talentTeacher);//达人导师/经纪人身份id
			orderDetail.setOrderId(orderInfoStoreIdMap.get(orderDetail.getStoreId()));
			orderDetail.setOrderObjectId(orderObject.getId());
			InventoryVo _check_inventory = _check_inventory_map.get(orderDetail.getInventoryId());
			orderDetail.setSalePrice(_check_inventory.getSalePrice());
			//				compOpenStoreDetailPrice(experience, orderObject, orderDetail,inventoryMap);
			orderDetail.setSettlementPrice(_check_inventory.getSettlementPrice());
			orderDetail.setTotalPrice(_check_inventory.getSalePrice() * orderDetail.getQuantity());
			orderDetail.setTotalSettlementprice(_check_inventory.getSettlementPrice() * orderDetail.getQuantity());

			//商品优惠抵扣金额（按商品销售应付金额占总交易应付金额比例分摊总优惠抵扣金额）
			int odPomotionDiscount = compODPomotionDiscount(userPromotion, orderObject, orderDetail, bgSalePriceMap);
			if (odPomotionDiscount == -1) {
				odPomotionDiscount = 0;
			} else {//按订单记录最后一个商品优惠抵扣金额
				int[] LastPomotionDiscountArr = { j, odPomotionDiscount };
				odLastPomotionDiscountMap.put(orderDetail.getOrderId(), LastPomotionDiscountArr);
			}
			orderDetail.setPromotionDiscount(odPomotionDiscount);

			//现金币
			int cashCoin = ((Double) (orderDetail.getTotalPrice().doubleValue() / orderObject.getTotalPrice() * orderObject.getCashCoin())).intValue();
			//店铺订单最后一行商品明细处理精度缺失
			if (j == _avl_goods_list.size() - 1 || orderDetail.getStoreId().intValue() != _avl_goods_list.get(j + 1).getStoreId().intValue()) {
				cashCoin = orderInfoIdMap.get(orderDetail.getOrderId()).getCashCoin() - (odAllCashCoinMap.get(orderDetail.getOrderId()) != null ? odAllCashCoinMap.get(orderDetail.getOrderId()) : 0);
			}
			orderDetail.setCashCoin(cashCoin);

			//商品应付金额
			int totalFee = orderDetail.getTotalPrice() - orderDetail.getPromotionDiscount() - orderDetail.getCashCoin();
			if (totalFee <= 0) {//FIXME 如果应付金额小于0，默认为0
				totalFee = 0;
			}
			//当订单应付金额累加大于等于实际订单应付总金额,当前应付为订单实际应付总金额-以累加订单商品应付金额=当前订单商品应付金额（用于处理精度缺失问题）
			if (((odAllTotalFeeMap.get(orderDetail.getOrderId()) != null ? odAllTotalFeeMap.get(orderDetail.getOrderId()) : 0) + totalFee) >= orderInfoIdMap.get(orderDetail.getOrderId()).getTotalFee()) {
				totalFee = orderInfoIdMap.get(orderDetail.getOrderId()).getTotalFee() - (odAllTotalFeeMap.get(orderDetail.getOrderId()) != null ? odAllTotalFeeMap.get(orderDetail.getOrderId()) : 0);
			}
			orderDetail.setTotalFee(totalFee);

			// orderDetail.setTalentAgio(talentAgio);
			//按订单分类，累加商品应付金额
			if (odAllTotalFeeMap.get(orderDetail.getOrderId()) == null) {
				odAllTotalFeeMap.put(orderDetail.getOrderId(), totalFee);
			} else {
				odAllTotalFeeMap.put(orderDetail.getOrderId(), (odAllTotalFeeMap.get(orderDetail.getOrderId()) != null ? odAllTotalFeeMap.get(orderDetail.getOrderId()) : 0) + totalFee);
			}
			//按订单分类，累加现金币
			if (odAllCashCoinMap.get(orderDetail.getOrderId()) == null) {
				odAllCashCoinMap.put(orderDetail.getOrderId(), cashCoin);
			} else {
				odAllCashCoinMap.put(orderDetail.getOrderId(), (odAllCashCoinMap.get(orderDetail.getOrderId()) != null ? odAllCashCoinMap.get(orderDetail.getOrderId()) : 0) + cashCoin);
			}
			//按订单分类，累加优惠抵扣金额
			if (odAllPomotionDiscountMap.get(orderDetail.getOrderId()) == null) {
				odAllPomotionDiscountMap.put(orderDetail.getOrderId(), odPomotionDiscount);
			} else {
				odAllPomotionDiscountMap.put(orderDetail.getOrderId(), (odAllPomotionDiscountMap.get(orderDetail.getOrderId()) != null ? odAllPomotionDiscountMap.get(orderDetail.getOrderId()) : 0) + odPomotionDiscount);
			}
		}
		//计算每个店铺订单最后一个商品的优惠抵扣金额（用于处理分摊优惠抵扣时的精度缺失）
		for (Map.Entry<Long, int[]> entry : odLastPomotionDiscountMap.entrySet()) {
			int[] arr = entry.getValue();
			OrderDetail orderDetail = _avl_goods_list.get(arr[0]);
			if (odAllPomotionDiscountMap.get(orderDetail.getOrderId()) != null) {
				_avl_goods_list.get(arr[0]).setPromotionDiscount(orderInfoIdMap.get(orderDetail.getOrderId()).getPromotionDiscount() - (odAllPomotionDiscountMap.get(orderDetail.getOrderId()) - arr[1]));
			}
		}
		//批量保存订单商品明细
		int odResult = orderDao.batchInsertOrderDetail(_avl_goods_list);
		if (odResult != 1) {
			throw new PlatformException(ErrorEnum.C20000, ErrorEnum.C20000.getMessage());
		}

		//清除购物车
		shoppingCartService.updateRemoveShoppingCart(_login_user, orderObject.getId());

		//计算分佣
		addCommision(_login_user, orderObject, _check_inventory_map, orderInfoIdMap, baseRestrictionsMap);

		if (orderObject.getCashCoin() > 0) {//记录现金币使用流水
			UserJournal userJournal = new UserJournal();
			userJournal.setUserId(orderObject.getUserId());
			userJournal.setOrderSn(orderObject.getOrderSn());
			userJournal.setPromotionDetailId(orderObject.getPromotionId());
			userJournal.setMoney(orderObject.getCashCoin());
			userJournal.setComment("订单消费");
			userJournal.setStatus(UserJournalStatusEnum.S7.getCode());
			userJournal.setType(CommonConstants.USER_JOURNAL_TYPE_SUB);
			int ujResult = userJournalService.insertUserJournal(userJournal);
			if (ujResult != 1) {
				throw new PlatformException(ErrorEnum.C20000, ErrorEnum.C20000.getMessage());
			}
		}
		respAddOrderInfo.setPayable(true);
		return resultModel;
	}

	/** 默认运费 */
	private int _get_default_freight() {
		return NumberUtils.toInt(Config.getString("orderFreight"), 0);
	}

	@Autowired
	private ShareGoodsMapper shareGoodsMapper;

	private boolean _check_share_goods_and_talent(GoodsSimpleVo req_goods, ResponseResultModel<RespGetOrderInfo> resultModel) {
		if (req_goods == null) {
			return false;
		}
		long talentId = req_goods.getTalentId();
		long talentShareGoodId = req_goods.getTalentShareGoodId();
		if ((talentId == 0 && talentShareGoodId > 0) || (talentId > 0 && talentShareGoodId == 0)) {
			resultModel.setError(ErrorEnum.C20403);
			return true;
		} else if (talentId > 0 && talentShareGoodId > 0) {
			//为兼容tanlentShareGoodId新老接口传值不同：老接口是分享商品记录id新接口是商品ID的问题
			//1.首先判断分享记录与分享人与购买商品id是否一致，一致为老接口，否则为新接口
			ShareGoods _check_share_goods = shareGoodsMapper.selectShareGoodsById(talentShareGoodId);
			if (_check_share_goods == null || _check_share_goods.getUserId() != talentId || _check_share_goods.getGoodId() != req_goods.getGoodId()) {
				try {
					_check_share_goods = shareGoodsMapper.selectShareGoodsByUserIdAndGoodIdAndAgio(talentId, talentShareGoodId);
				} catch (Exception e) {
					logger.error("用户{}分享商品{}出现异常：{}", talentId, talentShareGoodId, e.getMessage());
				}
			}
			if (_check_share_goods == null || _check_share_goods.getUserId() != talentId || _check_share_goods.getGoodId() != req_goods.getGoodId()) {
				resultModel.setError(ErrorEnum.C20403);
				return true;
			}
			if (req_goods.getTalentShareGoodId() != _check_share_goods.getId()) {
				req_goods.setTalentShareGoodId(_check_share_goods.getId());//FIXME 设置分享商品id为分享商品记录id，保证老接口数据一致
			}
		}
		return false;
	}

	/** 校验分享人与分享商品 */
	private boolean _check_share_goods_and_talent(Long goodsId, long talentId, long talentShareGoodId, ResponseResultModel<?> resultModel) {
		if ((talentId == 0 && talentShareGoodId > 0) || (talentId > 0 && talentShareGoodId == 0)) {
			resultModel.setError(ErrorEnum.C20403);
			return true;
		} else if (talentId > 0 && talentShareGoodId > 0) {
			ShareGoods _check_share_goods = shareGoodsMapper.selectShareGoodsById(talentShareGoodId);
			if (_check_share_goods == null || talentId != _check_share_goods.getUserId() || goodsId != _check_share_goods.getGoodId()) {
				resultModel.setError(ErrorEnum.C20403);
				return true;
			}
		}
		return false;
	}

	@Override
	protected void setOpenStoreUser(RequestOrderDetail requestOrderDetail, ResponseUser user, OrderObject orderObject) {
		//购买商品为B区&&(用户推荐人身份id不为空||购买商品达人id不为空)
		if (requestOrderDetail.getOrderDetailList().get(0).getGoodsType() == GoodsTypeEnum.T1.getCode() && (user.getRecommendFrom() != null && !user.getRecommendFrom().isEmpty() || requestOrderDetail.getOrderDetailList().get(0).getTalentId().longValue() > 0)) {
			//以购买商品分享达人id为主，如果没有取当前用户推荐人
			if (requestOrderDetail.getOrderDetailList().get(0).getTalentId().longValue() == 0) {
				UserInfo userInfo = userService.selectUserInfoByPersionId(user.getRecommendFrom());
				if (userInfo != null) {
					orderObject.setOpenStoreUserId(userInfo.getUserId());
				}
			} else {
				orderObject.setOpenStoreUserId(requestOrderDetail.getOrderDetailList().get(0).getTalentId());
			}
		}
	}

	@Override
	protected void compOpenStoreDetailPrice(int experience, OrderObject orderObject, OrderDetail orderDetail, Map<Long, InventoryVo> inventoryMap) {
		//FIXME 是开店单且商品为自营商品(与去交易单时判断不一致，缺少判断商品是否属于b区，目前b、c区不能同时支付，不会出现C区自营商品进行开店首单优惠情况)
		if (orderObject.getOpenStore() != null && orderObject.getOpenStore().intValue() == 1 && inventoryMap.get(orderDetail.getInventoryId()).getSelfSupport() == GoodsSelfTypeEnum.T0.getCode()) {
			inventoryMap.get(orderDetail.getInventoryId()).setSalePrice(inventoryMap.get(orderDetail.getInventoryId()).getSalePrice() * experience / 100);
		}
	}

	/** 返回开店优惠折扣，如果满足开店订单，标记订单为开店订单 */
	@Override
	protected int compOpenStorePrice(Map<String, BaseRestrictions> baseRestrictionsMap, int openStoreSelfFee, OrderObject orderObject) {
		int experience = baseRestrictionsMap.get(BaseRestrictionsEnum.T6.getText()).getExperience();
		if (openStoreSelfFee >= baseRestrictionsMap.get(BaseRestrictionsEnum.T6.getText()).getRestrictions()) {
			// orderObject.setTotalPrice(orderObject.getTotalPrice()-openStoreSelfFee+openStoreSelfFee*
			// baseRestrictionsMap.get(BaseRestrictionsEnum.T6.getText()).getExperience()/100);
			orderObject.setOpenStore(1);
		}
		return experience;
	}

	@Override
	protected OrderSettlement createOrderSettlement(Map<Long, OrderInfo> orderInfoIdMap, OrderDetail orderDetail, Map<Long, InventoryVo> inventoryMap, CompanyXz companyXz, boolean isSub, int currSettlementPriceDealer, int currCashCoinDealer, int currBalancePaidDealer) {
		OrderSettlement orderSettlement = createOrderSettlement(orderInfoIdMap, orderDetail, inventoryMap);
		orderSettlement.setGoodsType(orderDetail.getGoodsType());
		orderSettlement.setSelfSupport(inventoryMap.get(orderDetail.getInventoryId()).getSelfSupport());
		if (orderSettlement.getGoodsType().intValue() == GoodsTypeEnum.T0.getCode()) {
			orderSettlement.setCompanyAccount(Config.getString("xz.yeepay.yzAccount"));
		} else if (companyXz != null) {
			orderSettlement.setCompanyAccount(companyXz.getCompanyAccount());
			orderSettlement.setManagerAccount(companyXz.getManagerAccount());
		}
		orderSettlement.setSettlementRateDealer(inventoryMap.get(orderDetail.getInventoryId()).getSettlementRateDealer());
		orderSettlement.setSettlementRateManager(inventoryMap.get(orderDetail.getInventoryId()).getSettlementRateManager());
		// if(isSub)
		// {
		// orderSettlement.setSettlementPriceDealer((int)(Math.round((double)orderInfoIdMap.get(orderDetail.getOrderId()).getTotalFee()*orderSettlement.getSettlementRateDealer()/100))-currSettlementPriceDealer);
		// orderSettlement.setCashCoinDealer((int)(Math.round((double)orderInfoIdMap.get(orderDetail.getOrderId()).getCashCoin()*orderSettlement.getSettlementRateDealer()/100))-currCashCoinDealer);
		// }
		// else
		// {
		orderSettlement.setSettlementPriceDealer((int) (Math.round((double) orderDetail.getTotalFee() * orderSettlement.getSettlementRateDealer() / 100)));
		orderSettlement.setCashCoinDealer((int) (Math.round((double) orderDetail.getCashCoin() * orderSettlement.getSettlementRateDealer() / 100)));
		// }
		orderSettlement.setSettlementPriceManager(orderDetail.getTotalFee() - orderSettlement.getSettlementPriceDealer());
		orderSettlement.setCashCoinManager(orderDetail.getCashCoin() - orderSettlement.getCashCoinDealer());
		return orderSettlement;
	}

	@Override
	protected int compOIPomotionDiscount(UserPromotion userPromotion, OrderObject orderObject, OrderInfo orderInfo, Map<String, Integer> oinfoBGSalePriceMap, Map<Integer, Integer> bgSalePriceMap) throws PlatformException {
		int promotionDiscount = 0;
		if (userPromotion == null) {//优惠券不存在，默认优惠抵扣为0
			return promotionDiscount;
		}
		switch (userPromotion.getType()) {
			case 1://现金币
						//				promotionDiscount = orderInfo.getTotalPrice().intValue() / orderObject.getTotalPrice() * orderObject.getPromotionDiscount();
					//				break;
			case 2://通用券
			case 7://自主券
				promotionDiscount = (int) (orderInfo.getTotalPrice().doubleValue() / orderObject.getTotalPrice() * orderObject.getPromotionDiscount());
				break;
			case 3://品牌券
				if (!oinfoBGSalePriceMap.containsKey(orderInfo.getStoreId() + "_" + userPromotion.getBrandId())) {
					orderInfo.setPromotionId(0);
					promotionDiscount = -1;
				} else {
					promotionDiscount = (int) (MapUtils.getDoubleValue(oinfoBGSalePriceMap, orderInfo.getStoreId() + "_" + userPromotion.getBrandId(), 0d) / bgSalePriceMap.get(userPromotion.getBrandId()) * orderObject.getPromotionDiscount());
				}
				break;
			case 5://商品券
				if (!oinfoBGSalePriceMap.containsKey(orderInfo.getStoreId() + "_" + userPromotion.getGoodId())) {
					orderInfo.setPromotionId(0);
					promotionDiscount = -1;
				} else {
					promotionDiscount = (int) (MapUtils.getDoubleValue(oinfoBGSalePriceMap, orderInfo.getStoreId() + "_" + userPromotion.getGoodId() / bgSalePriceMap.get(userPromotion.getGoodId())) * orderObject.getPromotionDiscount());
				}
				break;
			default://优惠券不可用
				throw new PlatformException(ErrorEnum.C30110, ErrorEnum.C30110.getDesc());

		}
		return promotionDiscount;
	}

	@Override
	protected int compODPomotionDiscount(UserPromotion userPromotion, OrderObject orderObject, OrderDetail orderDetail, Map<Integer, Integer> bgSalePriceMap) {
		int promotionDiscount = 0;
		if (userPromotion == null) {
			return promotionDiscount;
		}
		switch (userPromotion.getType()) {
			case 1://现金币
						//				promotionDiscount = ((Double) (orderDetail.getTotalPrice().doubleValue() / orderObject.getTotalPrice() * orderObject.getPromotionDiscount())).intValue();
					//				break;
			case 2://通用券
			case 7://自主券
				promotionDiscount = (int) (orderDetail.getTotalPrice().doubleValue() / orderObject.getTotalPrice() * orderObject.getPromotionDiscount());
				break;
			case 3://品牌券
				if (orderDetail.getBrandId().intValue() != userPromotion.getBrandId()) {
					promotionDiscount = -1;
				} else {
					promotionDiscount = (int) (orderDetail.getTotalPrice().intValue() / MapUtils.getDoubleValue(bgSalePriceMap, userPromotion.getBrandId(), 0) * orderObject.getPromotionDiscount());
				}
				break;
			case 5://商品券
				if (orderDetail.getGoodId().intValue() != userPromotion.getGoodId()) {
					promotionDiscount = -1;
				} else {
					promotionDiscount = (int) (orderDetail.getTotalPrice().intValue() / MapUtils.getDoubleValue(bgSalePriceMap, userPromotion.getGoodId(), 0) * orderObject.getPromotionDiscount());
				}
				break;
		}
		return promotionDiscount;
	}

	@Override
	protected OpenStoreTypeEnum checkOpenStoreCommision(ResponseUser user, OrderObject orderObject, Map<String, ResponseUser> shareRecommendUserMap, Map<Long, ResponseUser> talentIdAndUserReMap, long talentId) {
		//首单且（存在普通推荐人身份或会员推荐人身份）
		if ((orderObject.getOpenStore() != null && orderObject.getOpenStore() == 1) && (shareRecommendUserMap.get(user.getRecommendFrom()) != null || talentIdAndUserReMap.get(talentId) != null)) {
			if (talentId == 0) {//不是达人分享
				if (shareRecommendUserMap.get(user.getRecommendFrom()).getLevel() == CommonConstants.TALENT_TEACHER_LEVEL) {//当前用户为讲师级别，讲师店
					return OpenStoreTypeEnum.T1;
				} else {//学生店
					return OpenStoreTypeEnum.T2;
				}
			} else {//达人商品
				if (talentIdAndUserReMap.get(talentId).getLevel() == CommonConstants.TALENT_TEACHER_LEVEL) {//达人为讲师级别
					return OpenStoreTypeEnum.T1;
				} else {//学生店
					return OpenStoreTypeEnum.T2;
				}
			}
		} else {
			return OpenStoreTypeEnum.T0;
		}
	}

	@Override
	protected int openStoreCommision(OpenStoreTypeEnum openStoreTypeEnum, int commisionPrice, Map<String, BaseRestrictions> baseRestrictionsMap, int fee, Map<Long, InventoryVo> inventoryMap, OrderDetail orderDetail) {
		//商品是自营且店铺类型是学生店，计算分佣比例
		if (inventoryMap.get(orderDetail.getInventoryId()).getSelfSupport() == GoodsSelfTypeEnum.T0.getCode() && openStoreTypeEnum.getCode() == OpenStoreTypeEnum.T2.getCode()) {
			fee = commisionPrice * baseRestrictionsMap.get(BaseRestrictionsEnum.T7.getText()).getExperience();
		}
		return fee;
	}

	@Override
	protected String openStoreComment(OpenStoreTypeEnum openStoreTypeEnum, String comment, Map<Long, InventoryVo> inventoryMap, OrderDetail orderDetail) {
		//商品是自营且开店店铺类型值大于0，标记为开店分佣
		if (inventoryMap.get(orderDetail.getInventoryId()).getSelfSupport() == GoodsSelfTypeEnum.T0.getCode() && openStoreTypeEnum.getCode() > 0) {
			comment = CommonConstants.COMMISION_DESC_OPEN_STORE;
		}
		return comment;
	}

	@Override
	protected int openStoreCommision2(OpenStoreTypeEnum openStoreTypeEnum, int commisionPrice, Map<String, BaseRestrictions> baseRestrictionsMap, int fee, Map<Long, InventoryVo> inventoryMap, OrderDetail orderDetail) {
		//自主商品且是学生店
		if (inventoryMap.get(orderDetail.getInventoryId()).getSelfSupport() == GoodsSelfTypeEnum.T0.getCode() && openStoreTypeEnum.getCode() == OpenStoreTypeEnum.T2.getCode()) {
			fee = commisionPrice * baseRestrictionsMap.get(BaseRestrictionsEnum.T7.getText()).getRestrictions();
		}
		return fee;
	}

	@Override
	protected void getUserPromotionOrderList(List<UserPromotionVo> userPromotionList, List<GoodsSimpleVo> goodsList) {
		int totalPrice = 0;
		Map<String, Integer> gbMap = new HashMap<String, Integer>();
		String goodsPrefix = "goods";
		String brandPrefix = "brand";
		boolean hasSelfGoods = false;
		boolean hasNoSelfGoods = false;
		for (GoodsSimpleVo goodsSimpleVo : goodsList) {
			if (!hasSelfGoods && goodsSimpleVo.getSelfSupport() == GoodsSelfTypeEnum.T0.getCode()) {
				hasSelfGoods = true;
			}
			if (!hasNoSelfGoods && goodsSimpleVo.getSelfSupport() == GoodsSelfTypeEnum.T1.getCode()) {
				hasNoSelfGoods = true;
			}
			String goodsKey = goodsPrefix + goodsSimpleVo.getGoodId();
			String brandKey = brandPrefix + goodsSimpleVo.getBrandId();
			if (gbMap.get(goodsKey) == null) {
				gbMap.put(goodsKey, goodsSimpleVo.getSalePrice() * goodsSimpleVo.getQuantity());
			} else {
				gbMap.put(goodsKey, goodsSimpleVo.getSalePrice() * goodsSimpleVo.getQuantity() + gbMap.get(goodsKey));
			}
			if (gbMap.get(brandKey) == null) {
				gbMap.put(brandKey, goodsSimpleVo.getSalePrice() * goodsSimpleVo.getQuantity());
			} else {
				gbMap.put(brandKey, goodsSimpleVo.getSalePrice() * goodsSimpleVo.getQuantity() + gbMap.get(brandKey));
			}
			totalPrice += goodsSimpleVo.getSalePrice() * goodsSimpleVo.getQuantity();
		}
		//		UserPromotionVo userPromotionTemp = null;
		//		int i = 0;
		List<UserPromotionVo> removeList = new ArrayList<UserPromotionVo>();
		for (UserPromotionVo userPromotion : userPromotionList) {
			switch (userPromotion.getType()) {
				case 1://妆币
					if (userPromotion.getLimited() > totalPrice) {
						removeList.add(userPromotion);
					} else {
						userPromotion.setDiscountAmount(userPromotion.getAmount());
						//						orderUserPromotionList(i, userPromotionTemp, userPromotion, userPromotionList);
					}
					break;
				case 2://现金券
					if (userPromotion.getLimited() > totalPrice) {
						removeList.add(userPromotion);
					} else {
						if (userPromotion.getIsDiscount() == 0) {
							userPromotion.setDiscountAmount(userPromotion.getAmount());
						} else {
							userPromotion.setDiscountAmount((100 - userPromotion.getDiscount()) * totalPrice / 100);
						}
						//						orderUserPromotionList(i, userPromotionTemp, userPromotion, userPromotionList);
					}
					break;
				case 3://品牌券
					if (gbMap.get(brandPrefix + userPromotion.getBrandId()) == null) {
						removeList.add(userPromotion);
					} else {
						if (userPromotion.getLimited() > gbMap.get(brandPrefix + userPromotion.getBrandId())) {
							removeList.add(userPromotion);
						} else {
							if (userPromotion.getIsDiscount() == 0) {
								userPromotion.setDiscountAmount(userPromotion.getAmount());
							} else {
								userPromotion.setDiscountAmount((100 - userPromotion.getDiscount()) * gbMap.get(brandPrefix + userPromotion.getBrandId()) / 100);
							}
							//							orderUserPromotionList(i, userPromotionTemp, userPromotion, userPromotionList);
						}
					}
					break;
				case 5://商品券
					if (gbMap.get(goodsPrefix + userPromotion.getGoodId()) == null) {
						removeList.add(userPromotion);
					} else {
						if (userPromotion.getLimited() > gbMap.get(goodsPrefix + userPromotion.getGoodId())) {
							removeList.add(userPromotion);
						} else {
							if (userPromotion.getIsDiscount() == 0) {
								userPromotion.setDiscountAmount(userPromotion.getAmount());
							} else {
								userPromotion.setDiscountAmount((100 - userPromotion.getDiscount()) * gbMap.get(goodsPrefix + userPromotion.getGoodId()) / 100);
							}
							//							orderUserPromotionList(i, userPromotionTemp, userPromotion, userPromotionList);
						}
					}
					break;
				case 7://自营非自营
					if (userPromotion.getLimited() > totalPrice) {
						removeList.add(userPromotion);
					} else if (userPromotion.getTargetSelfType() == GoodsSelfTypeEnum.T0.getCode() && hasNoSelfGoods || userPromotion.getTargetSelfType() == GoodsSelfTypeEnum.T1.getCode() && hasSelfGoods) {
						removeList.add(userPromotion);
					} else {
						if (userPromotion.getIsDiscount() == 0) {
							userPromotion.setDiscountAmount(userPromotion.getAmount());
						} else {
							userPromotion.setDiscountAmount((100 - userPromotion.getDiscount()) * totalPrice / 100);
						}
						//						orderUserPromotionList(i, userPromotionTemp, userPromotion, userPromotionList);
					}
					break;
				default://其它类型不可用
					removeList.add(userPromotion);
			}
			//			i++;
		}
		Collection<UserPromotionVo> existsAll = CollectionUtils.removeAll(userPromotionList, removeList);
		userPromotionList.clear();
		userPromotionList.addAll(existsAll);
		Collections.sort(userPromotionList, new UserPromotionComparator());
	}

	/** 封装异常商品 */
	private ErrorMsgGoods _pack_error_msg_goods(GoodsSimpleVo goodsSimpleVo, String errorMsg) {
		ErrorMsgGoods _add_err_goods = new ErrorMsgGoods();
		_add_err_goods.setGoodId(goodsSimpleVo.getGoodId());
		_add_err_goods.setGoodName(goodsSimpleVo.getGoodName());
		_add_err_goods.setSpecName(goodsSimpleVo.getSpecName());
		_add_err_goods.setGoodNavigateImage(goodsSimpleVo.getNavigateImg1());
		_add_err_goods.setInventoryId(goodsSimpleVo.getInventoryId());
		_add_err_goods.setMsg(errorMsg);
		return _add_err_goods;
	}

	/** b区商品，只支持易宝支付，其它使用除易宝以外所有支付方式 */
	private List<PayTypeConfig> getPayType() {
		//当前可用支付类型
		List<PayTypeConfig> payTypeConfigList = new ArrayList<PayTypeConfig>();
		//查询当前可用支付类型
		List<PayTypeConfig> payTypeConfigList0 = selectPayTypeConfigByStatus(StatusEnum.S1.getCode());
		for (PayTypeConfig payTypeConfig : payTypeConfigList0) {
			if (payTypeConfig.getPayType().intValue() >= PayTypeEnum.T20.getCode().intValue() && payTypeConfig.getPayType().intValue() <= PayTypeEnum.T24.getCode().intValue()) {
				payTypeConfigList.add(payTypeConfig);
			}
		}
		return payTypeConfigList;
	}

	@Override
	public int updateOrderObjectPayUrlById(long id, String payUrl) {
		return 0;
	}

	@Override
	public String selectDivideString(Long orderDetailId) {
		return null;
	}

	@Override
	public void updateOrderObjectFreightNo(Long orderObjectId, String refundFeeNo) {}

	@Override
	public int selectDetailGoodsType(Long id) {
		return 0;
	}

	@Override
	public String selectSettlementAccount(Long orderObjectId) {
		return null;
	}

	@Override
	public List<String> selectOrderClearing() {
		return null;
	}

	@Override
	public void OrderSettlementartificialEliminate(List<String> orderObjectSn) {}

	@Override
	public List<User> selectOrderRecommendFromUser(Long id) {
		return null;
	}

}
